package lhdx4;

public class Gongsi {
    String gongs;
    String zhuce;
    String dianHua;
    String jinYin;
    int k=0;
    double pinJ=0;
    Yuangong[] a=new Yuangong[45];
    public boolean add(String mame,int nianL,String xingB,String zhiW,int xinShui){
        if (k>=a.length){
            System.out.println("人已满！");
            return false;
        }
        a[k]=new Yuangong();
        a[k].mame=mame;
        a[k].nianL=nianL;
        a[k].xingB=xingB;
        a[k].zhiW=zhiW;
        if (xinShui>0) {
            a[k].xinShui = xinShui;
        }else {
            return false;
        }
        k++;
        pinJ=pinJ+xinShui;//总工资
        return true;
    }
    public void showInformation(){
        System.out.println("公司员工信息如下：");
        for (int i=0;i<k;i++){
            System.out.println(a[i].mame+"  "+a[i].nianL+"岁  "+a[i].xingB+" "+a[i].zhiW+" "+a[i].xinShui);
        }
    }
    public void ciTuei(String name){
        for (int i=0;i<k;i++){
            if (a[i].mame.equals(name)){
                pinJ=pinJ-a[i].xinShui;
                for (int j=i;j<k-1;j++){
                    a[j].mame=a[j+1].mame;
                    a[j].nianL=a[j+1].nianL;
                    a[j].xingB=a[j+1].xingB;
                    a[j].zhiW=a[j+1].zhiW;
                    a[j].xinShui=a[j+1].xinShui;
                }
                a[k-1].mame=null;
                a[k-1].nianL=0;
                a[k-1].xingB=null;
                a[k-1].zhiW=null;
                a[k-1].xinShui=0;
                k--;
                System.out.println("已辞退！");
                return;
            }
        }
        System.out.println("未找到！");
    }
    public void tongJi(){
        System.out.println("公司人数:"+k+"人");
    }
    public void findTopSalary(){
        int c=a[0].xinShui;
        int b=0;
        for (int i=0;i<k;i++){
            if (a[i].xinShui>=c){
                c=a[i].xinShui;
                b=i;
            }
        }
        String A=a[b].mame;
        System.out.println("薪水最高的员工是："+A);

    }
    public void sortBySalDesc(){
        Yuangong b;
        for (int i=0;i<k;i++){
            for (int j=0;j<k-i-1;j++){
                if (a[j].xinShui<a[j+1].xinShui){
                    b=a[j];
                    a[j]=a[j+1];
                    a[j+1]=b;
                }
            }
        }
        System.out.print("排序 ");
        for (int i=0;i<k;i++){
            System.out.print(a[i].xinShui + "  ");
        }
    }
    public double pingJun(){
        double pingjnug=pinJ/k;
        System.out.println("平均工资是："+pingjnug+"元。");
        return pingjnug;
    }
    public void zhang(){
        for (int i=0;i<k;i++){
            if (a[i].xinShui>=5000){
                a[i].xinShui=a[i].xinShui+100;
            }else {
                a[i].xinShui=a[i].xinShui+500;
            }
        }
        System.out.println("已涨工资！");
    }

}
